package main

import (
	"net/http"
	"smyx"
)

func main() {
	//获取http serve
	server := smyx.Create()
	//注册请求
	//curl -i http://localhost:18000/
	server.GET("/", func(c *smyx.Context) {
		c.HTML(http.StatusOK, "<h1>Hello Gee</h1>")
	})
	//curl "http://localhost:18000/hello?name=smyx"
	server.GET("/hello", func(c *smyx.Context) {
		c.String(http.StatusOK, "hello %s, you're %s\n", c.Query("name"), c.Path)
	})
	//curl "http://localhost:18000/login" -X POST -d 'username=smyx&password=123456'
	server.POST("/login", func(c *smyx.Context) {
		c.JSON(http.StatusOK, smyx.H{
			"username": c.PostForm("username"),
			"password": c.PostForm("password"),
		})
	})
	//启动serve
	err := server.Start(":18000")
	if err != nil {
		return
	}
}
